home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / dom / nsIBaseDOMException.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  7KB  |  125 lines

  1. /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 2002
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Peter Van der Beken <peterv@netscape.com> (original author)
  24.  *
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. #ifndef nsIBaseDOMException_h___
  41. #define nsIBaseDOMException_h___
  42.  
  43. #include "nsIDOMClassInfo.h"
  44.  
  45. // {1f13b201-39fa-11d6-a7f2-df501ff820dc}
  46. #define NS_BASE_DOM_EXCEPTION_CID  \
  47. { 0x1f13b201, 0x39fa, 0x11d6, \
  48. { 0xa7, 0xf2, 0xdf, 0x50, 0x1f, 0xf8, 0x20, 0xdc } }
  49.  
  50. // {731d9701-39f8-11d6-a7f2-b39073384c9c}
  51. #define NS_IBASEDOMEXCEPTION_IID  \
  52. { 0x731d9701, 0x39f8, 0x11d6, \
  53. { 0xa7, 0xf2, 0xb3, 0x90, 0x73, 0x38, 0x4c, 0x9c } }
  54.  
  55. class nsIBaseDOMException : public nsISupports {
  56. public:  
  57.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBASEDOMEXCEPTION_IID)
  58.  
  59.   NS_IMETHOD Init(nsresult aNSResult, const char* aName,
  60.                   const char* aMessage,
  61.                   nsIException* aDefaultException) = 0;
  62. };
  63.  
  64.  
  65. #define IMPL_DOM_EXCEPTION_HEAD(classname, ifname)                           \
  66. class classname : public nsIException,                                       \
  67.                   public ifname                                              \
  68. {                                                                            \
  69. public:                                                                      \
  70.   classname(nsIException* aInner);                                           \
  71.   virtual ~classname();                                                      \
  72.                                                                              \
  73.   NS_DECL_ISUPPORTS                                                          \
  74.   NS_FORWARD_NSIEXCEPTION(mBase->)
  75.  
  76. // Note: the exception implemented by this macro doesn't free the pointers
  77. //       it gets from the mapping_function and assumes they will be valid
  78. //       as long as the exception object is alive.
  79.  
  80. #define IMPL_DOM_EXCEPTION_TAIL(classname, ifname, domname, module,          \
  81.                                 mapping_function)                            \
  82. private:                                                                     \
  83.   nsCOMPtr<nsIException> mBase;                                              \
  84. };                                                                           \
  85.                                                                              \
  86. classname::classname(nsIException* aInner) : mBase(aInner)                   \
  87. {                                                                            \
  88. }                                                                            \
  89. classname::~classname() {}                                                   \
  90.                                                                              \
  91. NS_IMPL_ADDREF(classname)                                                    \
  92. NS_IMPL_RELEASE(classname)                                                   \
  93. NS_INTERFACE_MAP_BEGIN(classname)                                            \
  94.   NS_INTERFACE_MAP_ENTRY(nsIException)                                       \
  95.   NS_INTERFACE_MAP_ENTRY(ifname)                                             \
  96.   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)                \
  97.   NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(domname)                     \
  98. NS_INTERFACE_MAP_END                                                         \
  99.                                                                              \
  100. NS_DEFINE_CID(kBaseDOMException_CID_##domname, NS_BASE_DOM_EXCEPTION_CID);   \
  101.                                                                              \
  102. nsresult                                                                     \
  103. NS_New##domname(nsresult aNSResult, nsIException* aDefaultException,         \
  104.                 nsIException** aException)                                   \
  105. {                                                                            \
  106.   if (!(NS_ERROR_GET_MODULE(aNSResult) == module)) {                         \
  107.     NS_WARNING("Trying to create an exception for the wrong error module."); \
  108.     return NS_ERROR_FAILURE;                                                 \
  109.   }                                                                          \
  110.   const char* name;                                                          \
  111.   const char* message;                                                       \
  112.   mapping_function(aNSResult, &name, &message);                              \
  113.   nsCOMPtr<nsIBaseDOMException> baseException =                              \
  114.     do_CreateInstance(kBaseDOMException_CID_##domname);                      \
  115.   NS_ENSURE_TRUE(baseException, NS_ERROR_OUT_OF_MEMORY);                     \
  116.   baseException->Init(aNSResult, name, message, aDefaultException);          \
  117.   nsCOMPtr<nsIException> inner = do_QueryInterface(baseException);           \
  118.   *aException = new classname(inner);                                        \
  119.   NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY);                       \
  120.   NS_ADDREF(*aException);                                                    \
  121.   return NS_OK;                                                              \
  122. }
  123.  
  124. #endif /* nsIBaseDOMException_h___ */
  125.